package com.hotel.writer.controller;

import com.hotel.comm.bean.DubboReply;
import com.hotel.comm.bean.IReply;
import com.hotel.comm.service.search.ILuceneWriterService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class IndexWriterController {
    private static final Logger logger = LoggerFactory.getLogger(IndexWriterController.class);

    @Autowired
    private ILuceneWriterService luceneWriterService;

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/writePositionByCity")
    public void writePosition(@RequestParam(value = "cityId", defaultValue = "") String cityId,
                              HttpServletRequest request, HttpServletResponse response) {
        Long _cityId = null;
        if (StringUtils.isNotBlank(cityId)) {
            _cityId = Long.parseLong(cityId);
        }
        IReply reply = luceneWriterService.writePosition(_cityId);
        if (reply.isSuccess()) {
            logger.info("Write Position Success");
        } else {
            logger.info("Write Position Error: " + ((DubboReply) reply).getReplyMsg());
        }
    }

}
